package com.su.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.su.tools.PageData;


@Controller
@RequestMapping("/Portal")
public class PortalController  extends BaseController{

	@Resource(name = "portalService")
	private PortalService portalService;	
	
	@Resource(name = "applyUserService")
	private ApplyUserService applyUserService;	
	
	@Resource(name = "sysItemService")
	private SysItemService sysItemService;	
	
	@Resource(name="deptIntroduceService")
	private DeptIntroduceService deptIntroduceService;
	
	@RequestMapping(value = "/portal/{params}")
	@ResponseBody
	public Object getAppuserByUsernmae(@PathVariable String params, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		response.setHeader("Access-Control-Allow-Origin", "*");
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("params", params);
		JSONObject json = null;

		if (!pd.checkValue("orgCode")) {
			pd.put("orgCode", "0");
		}
		
		if (params.startsWith("CKL01")) {//CKL01:CHECKLOGIN判断当前用户是否登录
			json = applyUserService.invoke(pd);
		}else if(params.startsWith("REG01")){//REG:regist保存用户提交的注册信息
			json = applyUserService.invoke(pd);
		} else if(params.startsWith("LOG01")){//LGO:LOGIN登录验证并返回用户信息
			json = applyUserService.invoke(pd);
		} else if(params.startsWith("GITL01")){//GITL:getPartItemList获取最新发布项目信息
			json = sysItemService.invoke(pd);
		} else if(params.startsWith("GILP01")){//GILP01:getItemListBy分页获取最新发布项目信息
			json = sysItemService.invoke(pd);
		} else if(params.startsWith("GSI01")){//GSI01:getSingleItem根据主键获取单条项目信息GSI01   API01
			json = sysItemService.invoke(pd); 
		} else if(params.startsWith("API01")){//API01:applyItem申请项目   
			json = sysItemService.invoke(pd); 
		} else if(params.startsWith("UAU01")){//UAU01:update apply user更新申请人信息GPVE01
			json = applyUserService.invoke(pd); 
		} else if(params.startsWith("GPVE01")){ //GPVE01:get province更新申请人信息
			json = applyUserService.invoke(pd);
		} else if(params.startsWith("GDYM01")){//GDYM01:get dynamic info获取所有动态GDYMBYC01
			json = applyUserService.invoke(pd); 
		} else if(params.startsWith("GDYMBYPC01")){//GDYMBYC01:get dynamic by parent code获取所有动态GDYMBYC01
			json = applyUserService.invoke(pd); 
		} else if(params.startsWith("GDYMBYC01")){//GDYMBYC01:get dynamic by code获取所有动态
			json = applyUserService.invoke(pd); 
		} else if(params.startsWith("DT105")){//获取科室简介信息
			json = deptIntroduceService.invoke(pd); 
		} else if(params.startsWith("GPD01")){//GPD01:get part dynamic获取部分动态信息GPDPM01
			json = applyUserService.invoke(pd); 
		} else if(params.startsWith("GPDPM01")){//GPDPM01:get part department获取部分科室简介信息
			json = applyUserService.invoke(pd); 
		} else if(params.startsWith("EXLOG01")){//EXLOG01:exit login 退出登录
			json = applyUserService.invoke(pd); //
		} else if(params.startsWith("GPWD01")){//GPWD01:根据电话号码获取密码
			json = applyUserService.invoke(pd); //
		} else {
			json.put("code", "100");
			json.put("msg", "没有找到该业务代码!");
			return json;
		}
		return json;
	}
	
	
	
	
	
	//主页跳转
	@RequestMapping("/portalIndex")
	public String index(){
		return "/portal/portalIndex";
	}
	
	@RequestMapping("/instruction")
	public String instructionIndex(){
		return "/portal/institutionIntroduction";
	}

	@RequestMapping("/depDetail")
	public String depDetail(){
		return "/portal/depDetail";
	}
	
	
	//受试者志愿详情页面跳转
	@RequestMapping("/volunteeRecuit")
	public String volunteeRecuit(){
		return "/portal/volunteeRecruitment";
	}
	
	//受试者志愿申请页面跳转
	@RequestMapping("/volunteeApply")
	public String volunteeApply(Model model,Integer code){
		model.addAttribute("CODE", code);
		return "/portal/volunteeApply";
	}	
	//结构简介跳转
	@RequestMapping("/orgintroduction")
	public String orgintroduction(){
		return "/portal/orgintroduction";
	}	
	//登录页面跳转
	@RequestMapping("/portalLogin")
	public String portalLogin(Model model,String reUrl,String code){		
		model.addAttribute("reUrl", reUrl);
		//项目对应的主键
		model.addAttribute("code", code);
		return "/portal/portalLogin";
	}
	//注册页面跳转
	@RequestMapping("/portalRegist")
	public String portalRegist(){
		return "/portal/portalRegist";
	}	
	//忘记密码跳转
	@RequestMapping("/portalForgetPwd")
	public String portalForgetPwd(){
		return "/portal/portalForgetPwd";
	}	
	//跳转到用户中心
	@RequestMapping("/applyUserHome")
	public String applyUserHome(){
		return "/portal/applyUserHome";
	}	
	
	//跳转到机构动态详情页
	@RequestMapping("/institutionDetail")
	public String institutionDetail(String CODE,Model model){
		model.addAttribute("CODE", CODE);
		return "/portal/institutionDetail";
	}		

}
